package com.cvnert.testplatform.controller;


import com.cvnert.testplatform.domain.User;
import com.cvnert.testplatform.domain.vo.UserVo;
import com.cvnert.testplatform.service.UserService;
import com.cvnert.testplatform.utils.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/user")

public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 登录
     */
    @CrossOrigin(origins = "*")
    @PostMapping("/login")
    public ResultJson<Object> login(@RequestBody User user){
        return ResultJson.success(userService.login(user));
    }

    /**
     * 注册
     */
    @CrossOrigin(origins = "*")
    @PostMapping("/register")
    public ResultJson<Object> register(@RequestBody User user){
        return ResultJson.success(userService.register(user));
    }
    /**
     * 分页获取用户信息
     */
    @CrossOrigin(origins = "*")
    @PostMapping("/getUserList")
    public ResultJson<Object> getUserList(@RequestBody UserVo userVo){
        return ResultJson.success(userService.getUserList(userVo));
    }
    /**
     * 修改用户信息
     */
    @CrossOrigin(origins = "*")
    @PostMapping("/updateUser")
    public ResultJson<Object> updateUser(@RequestBody User user){
        return ResultJson.success(userService.updateUser(user));
    }
    /**
     * 删除用户
     */
    @CrossOrigin(origins = "*")
    @GetMapping("/deleteUser/{id}")
    public ResultJson<Object> deleteUser(@PathVariable Integer id){
        return ResultJson.success(userService.deleteUser(id));
    }
    /**
     * 通过id查询用户信息
     */
    @CrossOrigin(origins = "*")
    @GetMapping("/getUserById/{id}")
    public ResultJson<Object> getUserById(@PathVariable Integer id){
        return ResultJson.success(userService.getUserById(id));
    }
}
